/**
 * 列表全选、多选等通用操作
 * getDataList——获取列表数据
 * pageIndex——列表的起始页
 * pageSize——列表每页数据量
 * selectedRows——选中的列表数据*/
import {ref} from "vue";

export function useTableHandle(getDataList, tableOp){
    const {pageIndex, pageSize}=tableOp
    const selectedRows=ref([])
    function selectAllRow(selection) {
        selectedRows.value = selection
    }

    function cancelAllRow(selection) {
        selectedRows.value = selection
    }

    function selectRow(selection, row) {
        selectedRows.value = selection
    }

    function cancelRow(selection) {
        selectedRows.value = selection
    }

    function changePageIndex(value) {
        pageIndex.value = value
        getDataList()
    }

    function changePageSize(value) {
        pageSize.value = value
        getDataList()
    }
    function deleteRows(row) {
        console.log(selectedRows.value)
        console.log(row)
        getDataList()
    }

    return {
        selectedRows,
        selectAllRow,
        cancelAllRow,
        selectRow,
        cancelRow,
        changePageIndex,
        changePageSize,
        deleteRows,
    }
}